/**
 * Created by mar105 on 2019-03-05.
 */

import React, { Component } from 'react';
import { Layout, Form, Spin, Tabs, Avatar } from 'antd';
import CommonSales from './CommonBillEvent'; /* 继承销售模块业务功能 */
import * as commonFunc from './commonFunc'; /* 通用单据方法 */ /* 通用单据方法 */
import Toolbar from '../Common/ToolBar/ToolBarNew';
import StaticEditTable from './CommonTable'; /* 可编辑表格 */
import styles from '../../index.less';
import CommonView from './CommonView';
import CommonBase from './CommonBase'; /* 获取配置及数据 */
import * as commonBusiness from './commonBusiness'; /* 单据业务功能 */
import * as commonConfig from '../../utils/config';
import * as commonUtils from '../../utils/utils'; /* 通用方法 */

const { Header, Content } = Layout;
const { TabPane } = Tabs;
// const { confirm } = Modal;

class CommonBill extends Component {
  constructor(props) {
    super(props);
    this.state = {
    };
  }

  // ----------------------------数据修改回带end  ---------------------------- //

  render() {
    const { pageLoading } = this.props;
    return (
      <div>
        <Spin spinning={pageLoading}>
          <div>
            <BillComponent
              {...this.props}
              {...this.state}
            />
          </div>
        </Spin>
      </div>
    );
  }
}

const BillComponent = Form.create({
  mapPropsToFields(props) {
    const { masterData } = props;
    const obj = commonFunc.mapPropsToFields(masterData, Form);
    return obj;
  },
})((props) => {
  const {
    form, onReturnForm, slaveData, slavePagination,
  } = props;
  /*   回带表单   */
  onReturnForm(form);
  const pagination = {
    total: commonUtils.isEmptyArr(slaveData) ? 0 : slaveData.length,
    current: commonUtils.isEmptyObject(slavePagination) ? 1 : slavePagination.current,
    size: 'large',
    pageSize: commonConfig.pageSize,
    showQuickJumper: true,
  };
  const slaveTableProps = {
    ...commonBusiness.getTableTypes('slave', props),
    tableProps: { pagination, onChange: props.onTitleChange },
  };
  return (
    <Form>
      <Layout>
        <Header className={styles.header}>
          <Toolbar {...props} />
        </Header>
        <Layout className={styles.clayout}>
          <Content className={styles.content}>
            <CommonView {...props} />
            <div id="slaveTabs" className={styles.bShow}>
              <div>
                <Avatar src={props.imgSrc} />
              </div>
              <Tabs className={styles.slaveTabs}>
                <TabPane tab="主体内容" key={2}>
                  <StaticEditTable {...slaveTableProps} />
                </TabPane>
                <TabPane tab="审批信息" key={3}>
                  <StaticEditTable {...commonBusiness.getTableTypes('check', props)} />
                </TabPane>
              </Tabs>
            </div>
          </Content>
        </Layout>
      </Layout>
    </Form>
  );
});

export default CommonBase(CommonSales(CommonBill));
